package kr.couponplay.android.domain.message;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;

import kr.couponplay.android.domain.deal.Provider;

public class MessageList {
	private List<Item> messageItems = new ArrayList<Item>();
	
	public void addAll(List<Item> items) {
		this.messageItems.addAll(items);
		Collections.sort(messageItems);
	}

	public List<Item> getMessageItems(Provider provider) {
		if (provider == null) {
			return messageItems;
		}
		
		List<Item> provideMessageItems = new ArrayList<Item>();
		for (Item item : messageItems) {
			if (item.getProvider() == provider) {
				provideMessageItems.add(item);
			}
		}
		return provideMessageItems;
	}
	
	public static class Item implements Comparable<Item> {
		private Provider provider;
		private String address;
		private String message;
		private Date receivedDate;
		
		public Item(Provider provider, String address, String message, Date receivedDate) {
			this.provider = provider;
			this.address = address;
			this.message = message;
			this.receivedDate = receivedDate;
		}

		public Provider getProvider() {
			return provider;
		}

		public String getAddress() {
			return address;
		}

		public String getMessage() {
			return message;
		}

		public Date getReceivedDate() {
			return receivedDate;
		}

		@Override
		public int compareTo(Item item) {
			return item.getReceivedDate().compareTo(receivedDate);
		}
	}
}
